<template>
  <div>
    <el-table ref="table" :key="tableKey" v-loading="listLoading" element-loading-text="正在加载，请稍后" :data="list" border fit highlight-current-row style="width: 100%;" max-height="500px">
      <!-- <el-table-column type="selection" width="55" /> -->
      <el-table-column type="index" width="50" label="序号" />
      <!-- <el-table-column align="center" label="拖拽" width="80">
            <template slot-scope="{}">
              <svg-icon class="drag-handler" icon-class="drag" />
            </template>
          </el-table-column> -->
      <el-table-column label="字段名称" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.columnName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="字段注释" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.columnComment }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否主键" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.columnKey | dictLabel('sf') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否为空" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.columnNullable | dictLabel('sf') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据类型" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.dataType }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据长度" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.dataLength }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据精度" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.dataPrecision }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="标签" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.label }}</span>
        </template>
      </el-table-column> -->

    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" :page-sizes="pageArray" @pagination="setList" />
  </div>
</template>
<script>
import { fetchcolumnList } from '@/api/metadata/column'
import Pagination from '@/components/Pagination'
export default {
  name: 'baseTable',
  components: { Pagination },
  data() {
    return {
      tableKey: 0,
      list: null,
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 999,
      },
      total: 0,
      pageArray: this.$store.getters.pageArray,
    }
  },
  methods: {
    setList() {
      fetchcolumnList(this.listQuery).then((res) => {
        console.log(res, '列信息')
        this.list = res.data.data
      })
    },
    rest() {
      this.listQuery = {
        page: 1,
        limit: 999,
      }
    },
    getList(data) {
      this.rest()
      this.listQuery.sourceId = data.tableId
      fetchcolumnList(this.listQuery).then((res) => {
        console.log(res, '列信息')
        if (res.data.code == 0) {
          this.list = res.data.data
          this.total = res.data.total
        } else {
          this.$message.error(res.data.msg)
        }
      })
    },
  },
}
</script>
<style>
.pagination-container {
  margin-top: 0 !important;
}
</style>
